/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package syj.singletablemanager;

import java.io.File;

/**
 *
 * @author SYJ
 */
public class Demo
{
    private static String pathName = "G:/ProOffice/test.txt";

    private static boolean listFiles(File parentFile, SingleTableManager mng)
    {
        if (parentFile.isFile())
        {
            String[] values =
            {
                parentFile.getName(), parentFile.getPath()
            };
            mng.insert(values);
            return true;
        }
        if (parentFile.listFiles() == null)
        {
            return true;
        }
        for (File ele : parentFile.listFiles())
        {
            listFiles(ele, mng);
        }
        return true;
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception
    {
        //下面演示新建对象
        String[] columns =
        {
            "文件名", "带路径的完整文件名", "文件别名"
        };
        String[] argStrings =
        {
            "自定义参数1", "自定义参数2", "自定义参数3"
        };
        SingleTableManager mng1 = new SingleTableManager("D:/test.txt", columns, true, argStrings);

        //下面演示插入新值
        mng1.insert(new String[]
                {
                    "a.txt", "D:\\党建\\a.txt", "计算机党建记录"
                });
        mng1.insert(new String[]
                {
                    "b.doc", "D:\\党建\\b.doc", "通讯班党建记录"
                });

        //下面演示查找
        for (String ele : mng1.select(0, "a.txt"))
        {
            System.out.println(ele);
        }
        for (String ele : mng1.select(2, "通讯班党建记录"))
        {
            System.out.println(ele);
        }

        //下面演示修改
        String[] newValues = new String[]
        {
            "a2.docx", "D:\\党建\\a2.docx", "通信班党建记录"
        };
        mng1.update(newValues, 2, "通讯班党建记录");

        //下面演示删除
        mng1.delete(2, "计算机党建记录");

        //最后要写回
        mng1.writeBack();

        //下面演示根据已有文件创建管理对象
        SingleTableManager mng2 = new SingleTableManager("D:/test.txt");
    }
}
